<?php
class m_order extends spModel{
	function getOrder($oid){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		return $this -> find(array('oid'=>$oid));
	}
	
	function getOrders($status_out){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		return $this -> findAll(array('status_out'=>$status_out));
	}
	
	function doneOrder($oid){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		return $this -> update(array('oid'=>$oid),array('status_out'=>'1'));
	}
	
	function errorOrder($oid,$status_out){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		return $this -> update(array('oid'=>$oid),array('status_out'=>$status_out));
	}
	
	function updateOrder($oid,$tid,$alipay_no,$title,$topsession_id){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		if($this->getOrder($oid) === FALSE){
			return $this -> create(array('oid'=>$oid,'alipay_no'=>$alipay_no,'title'=>$title,'status_out'=>'0','topsession_id'=>$topsession_id,'tid'=>$tid));
		}
	}
	
	function setRefund($oid){
		$this->tbl_name = PREFIX.'orders';
		$this->pk = 'id';
		return $this -> update(array('oid'=>$oid,'status_out'=>'1'),array('status_out'=>'-1'));
	}
}